<?php
// +----------------------------------------------------------------------
// | SL 2018.8.17
// +----------------------------------------------------------------------
// | Copyright (c) 2018~2018 http://sl.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: zq <1040657944@qq.com>
// +----------------------------------------------------------------------

namespace app\common\model;


use think\Model;

class ForumCollectModel extends Model
{
    // 确定链接表名
    protected $name = 'forum_collect';
    //开启时间戳写入
    protected $autoWriteTimestamp = true;

    /**
     * 收藏
     */
    public function insertCollect($param)
    {
        if( $this->allowField(true)->save($param) ){
            return fmsg(0, '', '收藏成功!');
        }else{
            return fmsg(1, '', '收藏失败!');
        }
    }

    /**
     * 取消收藏
     */
    public function delCollect($param)
    {
        if( $this->where(['center_id'=>CID,'note_id'=>$param['note_id']])->delete() ){
            return fmsg(0, '', '取消收藏成功!');
        }else{
            return fmsg(1, '', '取消收藏失败!');
        }
    }

    /**
     * 找到一条收藏
     */
    public function findCollect($param)
    {
        if( $info = $this->where(['center_id'=>CID,'note_id'=>$param['note_id']])->find() ){
            return fmsg(0, '', '已收藏');
        }else{
            return fmsg(0, '', '未收藏');
        }
    }

    /**
     * 找到全部收藏
     */
    public function getCollect()
    {
        return $this->alias('a')
            ->join('z_forum_note n','a.note_id=n.id','LEFT')
            ->where('a.center_id',CID)
            ->field('n.title,a.note_id,a.create_time')
            ->order('a.create_time desc')
            ->select()->toArray();
    }



}